package org.skydiveapp;

import org.skydiveapplibrary.R;
import org.skydiveapplibrary.data.Constants;
import org.skydiveapplibrary.repository.SettingsRepository;

import com.actionbarsherlock.app.SherlockFragmentActivity;

import android.content.Intent;
import android.os.Bundle;

public class LogEntryEditActivity extends SherlockFragmentActivity implements LogEntryEditFragment.onLogEntryEditStatusChangedListener
{
	private static final int LOG_ENTRY_EDIT_REPLY_CLOSED = 10;
	
	@Override 
	public void onCreate(Bundle savedInstanceState)
	{ 
		SettingsRepository settingsRepository = new SettingsRepository(this);
		if (settingsRepository.getUseLightTheme())
			super.setTheme(R.style.SkydiveAppTheme_Light);
		
		super.onCreate(savedInstanceState);
		
		// show main view
		setContentView(R.layout.log_entry_edit_activity_view);
		
		if (findViewById(R.id.tabletLayout) != null)
		{
			LogEntryEditFragment logEntryEditFragment = (LogEntryEditFragment) getSupportFragmentManager()
			.findFragmentByTag(Constants.TAG_LOG_ENTRY_EDIT);
			
			// set result
            Intent intent =  new Intent();
            intent.putExtras(logEntryEditFragment.configureBundle(new Bundle()));
            setResult(RESULT_OK, intent);
            finish();
		}
	}

	@Override
	public void onLogEntryEditStatusChanged(int status)
	{
		if (status == LOG_ENTRY_EDIT_REPLY_CLOSED)
		{
			Intent intent =  new Intent();
            setResult(RESULT_OK, intent);
            
			finish();
		}
	}

	@Override
	public void onBackPressed()
	{
		LogEntryEditFragment logEntryEditFragment = (LogEntryEditFragment) getSupportFragmentManager()
				.findFragmentByTag(Constants.TAG_LOG_ENTRY_EDIT);
		logEntryEditFragment.requestClose();
	}
}